/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mweya.individuallab3;
/**
*
* @author mweya
*/
import java.util.ArrayList;
public class Driver {
public static void main(String[] args) {
// ArrayList for devices
ArrayList<Device> a = new ArrayList<Device>();
// Add devices to list
a.add(new Television(55, "Flat", "7736582", "Sansui", "Black", 77));
a.add(new Television(35, "Flat", "7572294", "Sony", "White", 199));
a.add(new Television(15, "CRT", "2885392", "Phillips", "Magenta", 12.4));
a.add(new ElectricOven(3, true, "3534634", "Dyson", "Teal", 244));
a.add(new ElectricOven(4, false, "38588213", "Defy", "Yellow", 2424));
a.add(new LEDBulb("Twist", "3545223", "Phillips", "Orange", 1.4));
a.add(new LEDBulb("Snap", "34786787", "Lexicon", "Red", 0.5));
a.add(new LEDBulb("Screw", "26357345", "Kekistani Industries Inc.", "Green", 4.20));
// Print all devices in list
System.out.println("Devices in a:");
int j = 0;
while (j<a.size()) {
System.out.println(a.get(j).toString());
j = j+1;
}
// Check if they are hazardous, adding them to h if they are
j = 0;
while (j<a.size()) {
Device temp = a.get(j);
if (temp instanceof Television) {
if ((((Television)temp).RFpowerRatio(55)) < 0) {
System.out.println(a.get(j).toString());
}
}
if (temp instanceof LEDBulb) {
if ((((LEDBulb)temp).RFpowerRatio(55)) < 0) {
System.out.println(a.get(j).toString());
}
}
if (temp instanceof ElectricOven) {
if ((((ElectricOven)temp).RFpowerRatio(55)) < 0) {
System.out.println(a.get(j).toString());
}
}
j = j+1;
}
// Sort based on power usage (low to high)
// This is hilariously inefficient, check my sorts page below
// for better ways to do this
//
// https://jl.mweya.duckdns.org/2019/DSA610S/Sorts/Main.java
ArrayList<Device> t = new ArrayList<Device>();
int s = a.size();
while (t.size() != s) {
j = 0;
Device lowest = a.get(0);
while (j<a.size()) {
double lowestPowerUsage = 0;
if (lowest instanceof Television) {
lowestPowerUsage = ((Television) lowest).powerUsage(1, 1);
}
if (lowest instanceof ElectricOven) {
lowestPowerUsage = ((ElectricOven) lowest).powerUsage(1, 1);
}
if (lowest instanceof LEDBulb) {
lowestPowerUsage = ((LEDBulb) lowest).powerUsage(1, 1);
}
double currentPowerUsage = 0;
Device current = a.get(j);
if (current instanceof Television) {
currentPowerUsage = ((Television) current).powerUsage(1, 1);
}
if (current instanceof ElectricOven) {
currentPowerUsage = ((ElectricOven) current).powerUsage(1, 1);
}
if (current instanceof LEDBulb) {
currentPowerUsage = ((LEDBulb) current).powerUsage(1, 1);
}
if (currentPowerUsage < lowestPowerUsage) {
lowest = current;
}
j = j+1;
}
t.add(a.get(a.indexOf(lowest)));
a.remove(lowest);
}
// Move sorted material to old arraylist and free up space
a = t;
t = null;
// Print list
System.out.println("Devices in a arranged by Power Usage:");
j = 0;
while (j<a.size()) {
System.out.println(a.get(j));
j = j+1;
}
}
}